import {activitiFomrBaseColumn} from "@/const/systemConstant";
import {baseUrl} from "@/config/env";

const globalFormVariable = {
    "#{baseUrl}": baseUrl
}
const createFormHideColumnMap = [
    activitiFomrBaseColumn.COLUMN_PROCESS_OPINION,
    activitiFomrBaseColumn.COLUMN_PROCESS_STATUS,
    activitiFomrBaseColumn.COLUMN_DEPT_ID,
]

const handlerFormHideColumnMap = [
    activitiFomrBaseColumn.COLUMN_PROCESS_OPINION,
    activitiFomrBaseColumn.COLUMN_PROCESS_STATUS,
]

function handlerFormConfigVariable(formOption) {
    if (!formOption) return
    let option = JSON.stringify(formOption);
    if (!globalFormVariable) return;
    for (let key in globalFormVariable) {
        option = option.replace(key, globalFormVariable[key]);
    }
    return JSON.parse(option);
}

function handlerFormColumn(formOption, hideColumnMap) {
    if (!formOption) return {}
    let column = formOption.column;
    if (!column) return formOption;
    for (let i = 0; i < column.length; i++) {
        let c = column[i];
        if (hideColumnMap.includes(c.prop)) {
            c.display = false;
        }
    }
    return formOption;
}

function activitStartMainFormCreate(formOption) {
    formOption = handlerFormConfigVariable(formOption)
    return handlerFormColumn(formOption, createFormHideColumnMap)
}

function activitiHandlerTaskMainForm(formOption) {
    if (!formOption) return {}
    formOption.emptyBtn = false;
    formOption.submitBtn = false;
    formOption = handlerFormConfigVariable(formOption)
    return handlerFormColumn(formOption, handlerFormHideColumnMap)
}

const activitiFormUtils = {
    activitStartMainFormCreate,
    activitiHandlerTaskMainForm,
    handlerFormConfigVariable
}

export default activitiFormUtils
